home *** CD-ROM | disk | FTP | other *** search
- --
- -- options menu page
- --
- function FormatName(szName)
- local c = strsub(szName, 1, 1);
- local szResult = strupper(c)..strsub(szName, 2);
-
- return szResult;
- end
-
-
- UI.PageCampaign=
- {
- GUI=
- {
- StartNewGameTab=
- {
- text = Localize("StartNewGame"),
- skin = UI.skins.TopMenuButton,
-
- greyedcolor = "12, 44, 6, 255",
-
- tabstop = 1,
-
- OnCommand = function(Sender)
- UI:DeactivateScreen("CampaignLoad");
- UI:ActivateScreen("CampaignStart");
- UI:DisableWidget("StartNewGameTab", "Campaign");
- UI:EnableWidget("LoadSavedGameTab", "Campaign");
- end
- },
-
- LoadSavedGameTab=
- {
- tabstop = 2,
-
- text = Localize("LoadSavedGame"),
- left = 379,
- skin = UI.skins.TopMenuButton,
-
- greyedcolor = "12, 44, 6, 255",
-
- OnCommand = function()
- UI:DisableWidget("LoadSavedGameTab", "Campaign");
- UI:EnableWidget("StartNewGameTab", "Campaign");
- UI:DeactivateScreen("CampaignStart");
- UI:ActivateScreen("CampaignLoad");
- end
- },
-
- OnInit = function(Sender)
- Game:CreateVariable("ai_autobalance", "0");
- end,
-
- OnActivate= function(Sender)
- Sender.StartNewGameTab.OnCommand(Sender.StartNewGameTab);
- end,
- },
- };
-
- UI.PageCampaignStart=
- {
- GUI=
- {
- Easy=
- {
- skin = UI.skins.CheckBox,
- left = 400, top = 245,
- width = 180, height = 32,
-
- text = Localize("Easy"),
-
- tabstop = 3,
- },
- Medium=
- {
- skin = UI.skins.CheckBox,
- left = 400, top = 285,
- width = 180, height = 32,
-
- text = Localize("Medium"),
-
- tabstop = 4,
- },
- Hard=
- {
- skin = UI.skins.CheckBox,
- left = 400, top = 325,
- width = 180, height = 32,
-
- text = Localize("Hard"),
-
- tabstop = 5,
- },
-
-
- AutoBalanceLabel=
- {
- skin = UI.skins.Label,
-
- left = 580-UI.skins.CheckBox.width-120, top = 365,
- width = 112,
-
- text=Localize("AIAutoBalance"),
- },
-
- AutoBalance=
- {
- skin = UI.skins.CheckBox,
- left = 580-UI.skins.CheckBox.width, top = 365,
-
- tabstop = 6,
-
- OnChanged = function(self)
- if (self:GetChecked()) then
- setglobal("ai_autobalance", 1);
- else
- setglobal("ai_autobalance", 0);
- end
- end,
- },
- -- only available in developer mode
- MapList=
- {
- tabstop = 7,
- skin = UI.skins.ListView,
-
- left = 580, top = 141,
- width = 200, height = 318,
-
- vscrollbar=
- {
- skin = UI.skins.VScrollBar,
- },
- hscrollbar=
- {
- skin = UI.skins.HScrollBar,
- },
-
- OnCommand = function (Sender)
- local iLevel = Sender:GetSelection(0);
-
- if (iLevel) then
- local szLevel = Sender:GetItem(iLevel);
- local szMission = Sender:GetSubItem(iLevel, 1);
-
- if (szLevel and strlen(szLevel)) then
- UI.PageCampaignStart.szLevelName = szLevel.." "..szMission;
-
- if (ClientStuff) then
- UI.YesNoBox(Localize("TerminateCurrentGame"), Localize("TerminateCurrentGameLabel"), UI.PageCampaignStart.ShowSplashScreen);
- else
- UI.PageCampaignStart.ShowSplashScreen();
- end
- end
- end
- end
- },
-
- StartGame=
- {
- text=Localize("Start"),
- left = 600,
- skin = UI.skins.BottomMenuButton,
-
- tabstop = 10,
-
- OnCommand=function(Sender)
- UI.PageCampaignStart.szLevelName = "Research Research"; -- is used by YesNoBox command
-
- if UI:IsWidgetVisible(UI.PageCampaignStart.GUI.MapList) and UI.PageCampaignStart.GUI.MapList:GetSelection(0) then
- UI.PageCampaignStart.GUI.MapList.OnCommand(UI.PageCampaignStart.GUI.MapList);
- else
- if (ClientStuff) then
- UI.YesNoBox(Localize("TerminateCurrentGame"), Localize("TerminateCurrentGameLabel"), UI.PageCampaignStart.ShowSplashScreen);
- else
- UI.PageCampaignStart.ShowSplashScreen();
- end
- end
- end,
- },
-
- OnActivate = function(Sender)
-
- if (System:IsDevModeEnable()~=1) then
- UI:HideWidget( UI.PageCampaignStart.GUI.MapList );
- else
- UI:ShowWidget( UI.PageCampaignStart.GUI.MapList );
- end
-
- -- TEMPORARY
- -- TEMPORARY
- UI.PageCampaignStart.GUI.MapList:Clear();
- UI.PageCampaignStart.GUI.MapList:ClearColumns();
- UI.PageCampaignStart.GUI.MapList:AddColumn("Level", 80, UIALIGN_LEFT);
- UI.PageCampaignStart.GUI.MapList:AddColumn("Mission", 100, UIALIGN_LEFT);
- for i, Table in DEFIANT do
- UI.PageCampaignStart.GUI.MapList:AddItem(Table[1], Table[2]);
- end
-
- UI.PageCampaignStart.GUI.Easy.OnChanged = UI.PageCampaignStart.DifficultyChanged;
- UI.PageCampaignStart.GUI.Medium.OnChanged = UI.PageCampaignStart.DifficultyChanged;
- UI.PageCampaignStart.GUI.Hard.OnChanged = UI.PageCampaignStart.DifficultyChanged;
-
- UI.PageCampaignStart.GUI.Easy:SetChecked(0);
- UI.PageCampaignStart.GUI.Medium:SetChecked(0);
- UI.PageCampaignStart.GUI.Hard:SetChecked(0);
-
- UI.PageCampaignStart.iDifficultyLevel = 1;
-
- if getglobal("game_Difficulty") then
- UI.PageCampaignStart.iDifficultyLevel = getglobal("game_Difficulty");
- end
-
- if (tonumber(UI.PageCampaignStart.iDifficultyLevel) == 0) then
- UI.PageCampaignStart.GUI.Easy:SetChecked(1);
- elseif (tonumber(UI.PageCampaignStart.iDifficultyLevel) == 1) then
- UI.PageCampaignStart.GUI.Medium:SetChecked(1);
- else
- UI.PageCampaignStart.GUI.Hard:SetChecked(1);
- end
-
- if (tonumber(getglobal("ai_autobalance")) ~= 0) then
- UI.PageCampaignStart.GUI.AutoBalance:SetChecked(1);
- else
- UI.PageCampaignStart.GUI.AutoBalance:SetChecked(0);
- end
-
- end
- },
-
- ShowSplashScreen = function()
- UI.SplashScreen(System:LoadImage("textures/controls"), nil, 1, 12, UI.PageCampaignStart.StartGame);
- end,
-
- StartGame = function()
- if (UI.PageCampaignStart.szLevelName) then
- setglobal("g_GameType", "Default");
-
- UI.PageCampaign:SetAIDifficulty(UI.PageCampaignStart.iDifficultyLevel);
-
- Game:SendMessage("StartLevel "..UI.PageCampaignStart.szLevelName);
- end
- UI.PageCampaignStart.szLevelName = nil;
- end,
-
- DifficultyChanged = function (Sender)
- UI.PageCampaignStart.GUI.Easy:SetChecked(0);
- UI.PageCampaignStart.GUI.Medium:SetChecked(0);
- UI.PageCampaignStart.GUI.Hard:SetChecked(0);
-
- Sender:SetChecked(1);
-
- if (Sender:GetName() == "Easy") then
- UI.PageCampaignStart.iDifficultyLevel = 0;
- elseif (Sender:GetName() == "Medium") then
- UI.PageCampaignStart.iDifficultyLevel = 1;
- else
- UI.PageCampaignStart.iDifficultyLevel = 2;
- end
-
- UI.PageCampaign:SetAIDifficulty(UI.PageCampaignStart.iDifficultyLevel);
- end
- }
-
- UI.PageCampaignLoad =
- {
- LevelList={},
- CheckpointName = {},
- iDifficultyLevel = 1,
- GUI=
- {
- CheckpointLabel=
- {
- skin = UI.skins.MenuBorder,
- left = 515, top = 147,
- width = 265, height = 28,
- bordersides = "tlr",
-
- halign = UIALIGN_CENTER,
-
- text = Localize("Checkpoint"),
- },
-
- CheckpointList=
- {
- skin = UI.skins.ListView,
- left = 515, top = 174,
- width = 265, height = 176,
-
- fontsize = 12,
-
- zorder = 10,
-
- tabstop = 4,
-
- vscrollbar=
- {
- skin = UI.skins.VScrollBar,
- },
- hscrollbar=
- {
- skin = UI.skins.HScrollBar,
- },
-
- OnChanged = function(Sender)
- UI.PageCampaignLoad:SetPicture();
- end
- },
-
- LevelLabel=
- {
- skin = UI.skins.MenuBorder,
- left = 205, top = 147,
- width = 300, height = 28,
-
- bordersides = "tlr",
-
- halign = UIALIGN_CENTER,
-
- text = Localize("Level");
- },
-
- LevelList=
- {
- skin = UI.skins.ListView,
- left = 205, top = 174,
- width = 300, height = 244,
-
- tabstop = 3,
-
- zorder = 10,
-
- vscrollbar=
- {
- skin = UI.skins.VScrollBar,
- },
-
- hscrollbar=
- {
- skin = UI.skins.HScrollBar,
- },
-
- OnChanged = function(Sender)
- UI.PageCampaignLoad.PopulateCheckpointList();
- end,
- },
-
- -- difficultystatic=
- -- {
- -- skin = UI.skins.Label,
- -- left = 140, top = 365,
- -- width = 182, height = 28,
-
- -- text = Localize("Difficulty"),
- -- },
-
- -- difficulty=
- -- {
- -- skin = UI.skins.ComboBox,
- -- left = 325, top = 365,
- -- width = 180, height = 28,
-
- -- OnChanged = function(Sender)
- -- UI.PageCampaignLoad.iDifficultyLevel = Sender:GetSelectionIndex()-1;
- -- end,
- -- },
-
- thumbnail=
- {
- skin = UI.skins.MenuBorder,
- left = 583, top = 356,
- width = 128, height = 96,
-
- color = "255 255 255 255",
- },
-
- profilenamestatic=
- {
- skin = UI.skins.Label,
- left = 140, top = 424,
- width = 182, height = 28,
-
- text = Localize("CurrentProfile"),
- },
-
- profilename=
- {
- skin = UI.skins.MenuStatic,
- halign = UIALIGN_LEFT,
-
- left = 325, top = 424,
- width = 180, height = 28,
- },
-
- loadgame=
- {
- text=Localize("Load_SaveGame"),
- left = 600,
- skin = UI.skins.BottomMenuButton,
-
- tabstop = 10,
-
- OnCommand=function(Sender)
-
- local iSelection = UI.PageCampaignLoad.GUI.CheckpointList:GetSelection(0);
-
- if not iSelection then
- return
- end
-
- UI.PageCampaignLoad.szFileName = UI.PageCampaignLoad.CheckpointName[iSelection];
-
- if (ClientStuff) then
- UI.YesNoBox(Localize("TerminateCurrentGame"), Localize("TerminateCurrentGameLabel"), UI.PageCampaignLoad.LoadGame);
- else
- UI.PageCampaignLoad.LoadGame();
- end
- end,
- },
-
- OnActivate = function(Sender)
-
- Sender.CheckpointList.OnCommand = Sender.loadgame.OnCommand;
-
- UI.PageCampaignStart.GUI.OnActivate(Sender);
-
- --UI.PageCampaignLoad.iDifficultyLevel = 1;
-
- --if getglobal("game_Difficulty") then
- --UI.PageCampaignLoad.iDifficultyLevel = getglobal("game_Difficulty");
- --end
-
- Sender.LevelList:Clear();
- Sender.CheckpointList:Clear();
- --Sender.difficulty:Clear();
- --Sender.difficulty:AddItem(Localize("Easy"));
- --Sender.difficulty:AddItem(Localize("Medium"));
- --Sender.difficulty:AddItem(Localize("Hard"));
-
- --Sender.difficulty:SelectIndex(UI.PageCampaignLoad.iDifficultyLevel+1);
-
- Sender.LevelList.OnCommand = Sender.loadgame.OnCommand;
- Sender.LevelList:Clear();
-
- local szProfileName = getglobal("g_playerprofile");
-
- if ((not szProfileName) or (strlen(szProfileName) < 1)) then
- szProfileName = "default";
- g_playerprofile = "default";
- end
-
- Sender.profilename:SetText(szProfileName);
-
- UI.PageCampaignLoad.SaveList = nil;
- UI.PageCampaignLoad.SaveList = Game:GetSaveGameList(szProfileName);
-
- UI.PageCampaignLoad.LevelList = {};
- local LevelList = UI.PageCampaignLoad.LevelList;
-
- for i, SaveGame in UI.PageCampaignLoad.SaveList do
- if (not LevelList[SaveGame.Level]) then
- LevelList[SaveGame.Level] = {};
- end
- tinsert(LevelList[SaveGame.Level], SaveGame);
-
- -- remove the "n" that lua just inserts (tinsert call)
- LevelList[SaveGame.Level].n = nil;
- end
-
- UI.PageCampaignLoad:PopulateLevelList();
- UI.PageCampaignLoad:SetPicture();
- end,
- },
-
- SetPicture = function()
- local iSelection = UI.PageCampaignLoad.GUI.CheckpointList:GetSelection(0);
-
- if iSelection then
-
- local szFileName = UI.PageCampaignLoad.CheckpointName[iSelection];
-
- if (szFileName and strlen(szFileName) > 1) then
-
- szFileName = "profiles/player/"..getglobal("g_playerprofile").."/savegames/"..szFileName;
-
- local iTexture = System:LoadImage(szFileName);
-
- if (iTexture) then
- UI.PageCampaignLoad.GUI.thumbnail:SetColor("255 255 255 255");
- UI.PageCampaignLoad.GUI.thumbnail:SetTexture(iTexture);
-
- return;
- end
- end
- end
-
- UI.PageCampaignLoad.GUI.thumbnail:SetColor("0 0 0 64");
- UI.PageCampaignLoad.GUI.thumbnail:SetTexture(nil);
- end,
-
- LoadGame = function()
- printf(UI.PageCampaignLoad.szFileName);
- if (UI.PageCampaignLoad.szFileName) then
- --UI.PageCampaign.SetAIDifficulty(UI.PageCampaignLoad.iDifficultyLevel);
-
- setglobal("g_GameType","Default");
-
- Game:SendMessage("LoadGame "..UI.PageCampaignLoad.szFileName);
- end
-
- UI.PageCampaignLoad.szFileName = nil;
- end,
-
- PopulateLevelList = function()
- local LevelList = UI.PageCampaignLoad.LevelList;
- local ListView = UI.PageCampaignLoad.GUI.LevelList;
-
- ListView:Clear();
-
- -- this is needed so that the levels are in order of appearence
- -- it's not efficient, but it's fast implemented, and no changes needed
- for i, Level in DEFIANT do
- for szLevelName, CheckPointList in LevelList do
- if (strlower(tostring(szLevelName)) == strlower(tostring(Level[1]))) then
- ListView:AddItem(FormatName(szLevelName));
- break;
- end
- end
- end
- end,
-
- PopulateCheckpointList = function()
- local LevelList = UI.PageCampaignLoad.LevelList;
- local LevelListView = UI.PageCampaignLoad.GUI.LevelList;
- local ListView = UI.PageCampaignLoad.GUI.CheckpointList;
-
- ListView:Clear();
- UI.PageCampaignLoad.CheckpointName = {};
-
- local iSelection = LevelListView:GetSelection(0);
-
- if (iSelection) then
- local CheckpointList = LevelList[strlower(LevelListView:GetItem(iSelection))];
-
- if (CheckpointList) then
-
- local iCPCount = count(CheckpointList);
-
- for i=1, iCPCount do
- -- remove the .sav part
- local Checkpoint = CheckpointList[i];
- local szFileName = strsub(Checkpoint.Filename, 1, strlen(Checkpoint.Filename)-strlen(".sav"));
- local szCheckpointName;
-
- if (i == iCPCount) then
- szCheckpointName = format("Checkpoint %d %.2d/%.2d/%.2d [%.2d:%.2d] last", i, Checkpoint.Month, Checkpoint.Day, Checkpoint.Year, Checkpoint.Hour, Checkpoint.Minute);
- else
- szCheckpointName = format("Checkpoint %d %.2d/%.2d/%.2d [%.2d:%.2d]", i, Checkpoint.Month, Checkpoint.Day, Checkpoint.Year, Checkpoint.Hour, Checkpoint.Minute);
- end
-
- UI.PageCampaignLoad.CheckpointName[ListView:InsertItem(0, szCheckpointName)] = szFileName;
- end
- end
- end
-
- UI.PageCampaignLoad:SetPicture();
-
- --UI.PageCampaignLoad.GUI.CheckpointList:SortEx(UISORT_DESCENDING, 0);
- end
- }
-
- function UI.PageCampaign:SetAIDifficulty(difficultylevel)
-
- setglobal("game_Difficulty", difficultylevel);
-
- if game_Difficulty==0 then -- easy
- System:Log("UI.PageCampaign:SetAIDifficulty easy");
- setglobal("game_Accuracy",0.4);
- setglobal("game_Aggression",0.4);
- setglobal("game_Health",0.4);
- setglobal("ai_allow_accuracy_decrease",1);
- setglobal("ai_allow_accuracy_increase",0);
-
- elseif game_Difficulty==1 then -- medium
- System:Log("UI.PageCampaign:SetAIDifficulty medium");
- setglobal("game_Accuracy",0.7);
- setglobal("game_Aggression",0.7);
- setglobal("game_Health",0.7);
- setglobal("ai_allow_accuracy_decrease",0);
- setglobal("ai_allow_accuracy_increase",1);
-
- elseif game_Difficulty==2 then -- hard
- System:Log("UI.PageCampaign:SetAIDifficulty hard");
- setglobal("game_Accuracy",1.0);
- setglobal("game_Aggression",1.0);
- setglobal("game_Health",1.0);
- setglobal("ai_allow_accuracy_decrease",1);
- setglobal("ai_allow_accuracy_increase",1);
- end
- end
-
-
- AddUISideMenu(UI.PageCampaign.GUI,
- {
- { "MainMenu", Localize("MainMenu"), "$MainScreen$", 0},
- { "Options", Localize("Options"), "Options", },
- });
-
- UI:CreateScreenFromTable("CampaignStart",UI.PageCampaignStart.GUI);
- UI:CreateScreenFromTable("CampaignLoad",UI.PageCampaignLoad.GUI);
- UI:CreateScreenFromTable("Campaign",UI.PageCampaign.GUI);